package org.example.lost.service.impl;

import org.example.lost.entity.Kind;
import org.example.lost.entity.dto.KindDTO;
import org.example.lost.mapper.KindMapper;
import org.example.lost.service.KindService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author hxy
 * @Date 2021/3/24 20:53
 * @Version 1.0
 */
@Service
public class KindServiceImpl implements KindService {
    @Autowired
    KindMapper kindMapper;

    @Override
    public List<KindDTO> getList() {
        List<KindDTO> kindDTOS=kindMapper.selectList();

        return kindDTOS;
    }

    @Override
    public int addKind(KindDTO kindDTO) {
        Kind kind=new Kind();
        BeanUtils.copyProperties(kindDTO,kind);
        kind.setKindId(UUID.randomUUID().toString().replace("-",""));
        kind.setCreateTime(new Date());
        kind.setUpdateTime(new Date());
        int result = kindMapper.insert(kind);
        return result;
    }

    @Override
    public int delete(String kindId) {
        int result = kindMapper.delete(kindId);
        return result;
    }
}
